package com.example.dllo.baidumusic.nettool;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.bmob.v3.Bmob;

/**
 * Created by dllo on 16/8/15.
 */
public abstract class BaseFragment extends Fragment {
    protected Context mContext;//所有的子类都会有这样的context对象

    //可以给adapter,dialog 使用
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (setLayout() == 0) {
            Log.d("BaseFragment", this.getClass().getSimpleName() + "没有绑定布局");
            return super.onCreateView(inflater, container, savedInstanceState);
        }
        return inflater.inflate(setLayout(), container, false);
    }

    protected abstract
    @LayoutRes
    int setLayout();

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        Bmob.initialize(getContext(), "ff261edc10ca4a638d4f5a53c4130e65");
    }

    //
    protected abstract void initView();

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    //初始化数据,例如网络请求,查询数据库等
    protected abstract void initData();

    //fragment 本身的组件 来做findById 的操作时调用
    //会在
    protected <T extends View> T bindView(int id) {
        return (T) getView().findViewById(id);
    }

    //当要findById
    protected <T extends View> T bindView(View view, int id) {
        return (T) view.findViewById(id);
    }
}
